import 'dart:convert';

import 'package:aitao_flutter/model/im/video_chat_model.dart';
import 'package:flutter/cupertino.dart';
import 'package:get/get.dart';

class VideoChatController extends GetxController {
  VideoChatModel? model;
  // 填写项目的 App ID，可在声网控制台中生成
  String appId = "40134fdc1c4b47de8e2f51f16b334f3e";
  // 填写声网控制台中生成的临时 Token
  String token = "";
  // 填写频道名
  String channel = "<-- Insert Channel Name -->";
  String? type;
  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    debugPrint('视频通话控制器初始化');
    if (Get.parameters['type'] != null) {
      type = Get.parameters['type'];
      update();
    }
    if (Get.parameters['model'] != null) {
      VideoChatModel m = VideoChatModel.fromJson(
          json.decode(Get.parameters['model'].toString()));
      debugPrint('m:${m.roomId}');
      model = m;
      token = model?.agoraToken ?? '';
      channel = model!.roomId.toString();
      update();
    }
  }

  @override
  void onClose() {
    // TODO: implement onClose
    super.onClose();
    debugPrint('视频通话控制器onClose');
  }
}
